package main

import (
	"sync"

	"gitee.com/shexk/plugin"
	"gitee.com/shexk/sfp/stl"
)

type App struct {
	appobj    *plugin.AppObj
	pluginmng *stl.PluginManager
}

var (
	instance_app *App
	once_app     sync.Once
)

func GetApp() *App {
	once_app.Do(func() {
		// 数据总线，用于应用间通信
		stl.GetDBCmd().OpenDB("fimq.db")
		version := stl.GetDBCmd().ReadKeyValue("Version")
		stl.GetLog().WriteLog(stl.Log_Info, "System Version:"+version)

		appObj := plugin.NewAppObj(stl.GetDBCmd().GetDB())
		pm := stl.NewPluginManager(appObj)
		instance_app = &App{appobj: appObj, pluginmng: pm}
	})
	return instance_app
}

func (app *App) Start() {
	// 加载所有插件
	app.pluginmng.LoadAllPlugin()
}
